<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="mini" v-show="showSearch" label-width="68px">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-form-item label="项目区域" prop="projectRegion">
        <el-select v-model="queryParams.projectRegion" placeholder="请选择" clearable @keyup.enter.native="handleQuery">
          <el-option v-for="dict in dict.type.cld_project_region" :key="dict.value" :label="dict.label"
            :value="parseInt(dict.value)"></el-option>
        </el-select>
      </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="项目名称" prop="projectName">
        <el-input v-model="queryParams.projectName" placeholder="请输入" clearable @keyup.enter.native="handleQuery" />
      </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label-width="10px">
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
        </el-col>
      </el-row>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd"
          v-hasPermi="['cld:restbreaks:add']">新建排休</el-button>
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['cld:restbreaks:export']"
        >导入</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['cld:restbreaks:export']"
        >列表导出</el-button>
      </el-col> -->
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="restbreaksList" border>
      <el-table-column label="月份" align="center">
        <template slot-scope="scope">
          {{ scope.row.restbreakMonth < 10 ? (scope.row.restbreakYear + '-' + '0' + scope.row.restbreakMonth) :
            scope.row.restbreakYear + '-' + scope.row.restbreakMonth }} </template>
      </el-table-column>
      <el-table-column label="项目区域" align="center" prop="projectRegion">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.cld_project_region" :value="scope.row.projectRegion" />
        </template>
      </el-table-column>
      <el-table-column label="项目名称" align="center" prop="projectName" />
      <el-table-column label="员工人数" align="center" prop="staffNumber" />
      <el-table-column label="排休次数" align="center" prop="isConfirm">
        <template slot-scope="scope">
          {{ scope.row.retired + '/' + scope.row.projectSet.allMonthlyDay * scope.row.staffNumber }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" @click="handleUpdate(scope.row)"
            v-hasPermi="['cld:restbreaks:query']">日历查看</el-button>
          <el-button size="mini" type="text" @click="handleView(scope.row)"
            v-hasPermi="['cld:restbreaks:query']">列表查看</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
  </div>
</template>

<script>
import { listRestbreaks} from "@/api/cld/restbreaks";

export default {
  name: "Restbreaks",
  dicts: ['cld_project_region'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 排休管理表格数据
      restbreaksList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        projectRegion: null,
        projectName: null
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询排休管理列表 */
    getList() {
      this.loading = true;
      listRestbreaks(this.queryParams).then(response => {
        this.restbreaksList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 新建排休
    handleAdd() {
      this.$router.push("/restbreaks/add-scheduling/addScheduling/0");
    },
    // 编辑排休
    handleUpdate(row) {
      this.$router.push("/restbreaks/add-scheduling/addScheduling/" + row.restbreakId);
    },
    // 查看排休
    handleView(row){
      this.$router.push("/restbreaks/viewSchedule/view/" + row.restbreakId);
    }
  }
};
</script>
